package com.accesshollywood.grfxOrdering.Dialogs;

import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Window;
import java.awt.Dialog.ModalityType;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.text.ParseException;

import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JFormattedTextField;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.border.EmptyBorder;
import javax.swing.text.MaskFormatter;

import com.accesshollywood.grfxOrdering.basics.ShowNames;
import com.accesshollywood.indexables.ShowName;

public class NewShowNameDialog extends AbstractCustomDialog {
	private final JPanel contentPanel = new JPanel();
	private JTextField txt;
	private JTextField txtNickname;
	private JTextField txtName;
	private JTextField textField_1;

	public NewShowNameDialog(Window w, ModalityType modality){
		super(w, modality);
		setModal(true);
		
		createDialog();
	}

	/**
	 * Create the dialog.
	 */
	public void createDialog() {
		setBounds(100, 100, 293, 155);
		setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
		getContentPane().setLayout(new BorderLayout());
		contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
		getContentPane().add(contentPanel, BorderLayout.CENTER);
		contentPanel.setLayout(new BoxLayout(contentPanel, BoxLayout.Y_AXIS));
		{
			JPanel panel = new JPanel();
			panel.setAlignmentX(Component.LEFT_ALIGNMENT);
			contentPanel.add(panel);
			panel.setLayout(new BoxLayout(panel, BoxLayout.X_AXIS));
			{
				JLabel lblNewLabel = new JLabel("ShowName");
				panel.add(lblNewLabel);
				
				txtName = new JTextField();
				txtName.setMinimumSize(new Dimension(200, 20));
				txtName.setMaximumSize(new Dimension(200, 20));
				panel.add(txtName);
				txtName.setColumns(10);
			}
			
			Component rigidArea_1 = Box.createRigidArea(new Dimension(20, 20));
			contentPanel.add(rigidArea_1);
			
			JPanel panel1 = new JPanel();
			panel1.setAlignmentX(Component.LEFT_ALIGNMENT);
			contentPanel.add(panel1);
			panel1.setLayout(new BoxLayout(panel1, BoxLayout.X_AXIS));
			{
				JLabel lblNewLabel = new JLabel("  NickName");
				panel1.add(lblNewLabel);
				
				try {
					txtNickname = new JFormattedTextField(new MaskFormatter("**********"));
					txtNickname.setMinimumSize(new Dimension(100, 20));
					txtNickname.setMaximumSize(new Dimension(100, 20));
					panel1.add(txtNickname);
					txtNickname.setColumns(10);
				} catch (ParseException e) {
					e.printStackTrace();
				}
			}
		}
		
		Component rigidArea = Box.createRigidArea(new Dimension(20, 20));
		contentPanel.add(rigidArea);
		{
			JPanel buttonPane = new JPanel();
			buttonPane.setLayout(new FlowLayout(FlowLayout.RIGHT));
			getContentPane().add(buttonPane, BorderLayout.SOUTH);
			{
				JButton okButton = new JButton("OK");
				okButton.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent arg0) {
						OK();
					}
				});
				okButton.setActionCommand("OK");
				buttonPane.add(okButton);
				getRootPane().setDefaultButton(okButton);
			}
			{
				JButton cancelButton = new JButton("Cancel");
				cancelButton.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent arg0) {
						cancel();
					}
				});
				cancelButton.setActionCommand("Cancel");
				buttonPane.add(cancelButton);
			}
		}
		
		setLocationRelativeTo(null);
		
		this.setVisible(true);
	}
	
	public void OK(){
		makeShowName();
		this.dispose();
	}
	
	public void cancel(){
		this.dispose();
	}
	
	public void makeShowName(){
		ShowName newShowName = new ShowName();
		newShowName.name = txtName.getText();
		newShowName.nickName = txtNickname.getText();

		ShowNames.addShowNameToLists(newShowName);
		ShowNames.addShowNameToSQL(newShowName);
	}
}
